package com.ruoyi.web.controller.trans;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trans.domain.BaSupplier;
import com.ruoyi.trans.service.IBaSupplierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商Controller
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@Controller
@RequestMapping("/trans/supplier")
public class BaSupplierController extends BaseController
{
    private String prefix = "trans/supplier";

    @Autowired
    private IBaSupplierService baSupplierService;

    @RequiresPermissions("trans:supplier:view")
    @GetMapping()
    public String supplier()
    {
        return prefix + "/supplier";
    }

    /**
     * 查询供应商列表
     */
    @RequiresPermissions("trans:supplier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaSupplier baSupplier)
    {
        startPage();
        List<BaSupplier> list = baSupplierService.selectBaSupplierList(baSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */
    @RequiresPermissions("trans:supplier:export")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaSupplier baSupplier)
    {
        List<BaSupplier> list = baSupplierService.selectBaSupplierList(baSupplier);
        ExcelUtil<BaSupplier> util = new ExcelUtil<BaSupplier>(BaSupplier.class);
        return util.exportExcel(list, "供应商数据");
    }

    /**
     * 新增供应商
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商
     */
    @RequiresPermissions("trans:supplier:add")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaSupplier baSupplier)
    {
        baSupplier.setCreateBy(getLoginName());
        return toAjax(baSupplierService.insertBaSupplier(baSupplier));
    }

    /**
     * 修改供应商
     */
    @RequiresPermissions("trans:supplier:edit")
    @GetMapping("/edit/{sId}")
    public String edit(@PathVariable("sId") Long sId, ModelMap mmap)
    {
        BaSupplier baSupplier = baSupplierService.selectBaSupplierBySId(sId);
        mmap.put("baSupplier", baSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商
     */
    @RequiresPermissions("trans:supplier:edit")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaSupplier baSupplier)
    {
        baSupplier.setUpdateBy(getLoginName());
        return toAjax(baSupplierService.updateBaSupplier(baSupplier));
    }

    /**
     * 删除供应商
     */
    @RequiresPermissions("trans:supplier:remove")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baSupplierService.deleteBaSupplierBySIds(ids));
    }
}
